
const Koa = require('koa');
const Router = require('koa-router');

const app = new Koa();
//前置,层级.如果需要在router前面增加层级
// const router = new Router();

//子路由
let home = new Router();
home
    .get('/jspang',async(ctx) =>{
        ctx.body = 'Home --> JSPang Page'
    })
    .get('/todo',async(ctx) =>{
        ctx.body = 'Home --> Todo Page'
    })

//子路由
let page = new Router();
page
    .get('/jspang',async(ctx) =>{
        ctx.body = 'Page --> JSPang Page'
    })
    .get('/todo',async(ctx) =>{
        ctx.body = 'Page --> Todo Page'
    })


//主路由,相当于父级,装载子级路由
let router = new Router();
router.use('/home',home.routes(),home.allowedMethods());
router.use('/page',page.routes(),page.allowedMethods());

//加载中间件,加载应用
app
    .use(router.routes())
    .use(router.allowedMethods())

app.listen(3000,() =>{
     
    console.log('[class6] server is starting at port 3000!');
    
})